package Controller1;
import java.net.URL;
import java.util.ResourceBundle;
import Dao.staffDao;
import Model1.staff;
import javax.swing.JOptionPane;
import Model1.sender;
import Controller1.GoodsController;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import java.lang.Integer;
import java.net.URL;
import java.lang.Exception;
public class MainViewController implements Initializable {
	@FXML
	private TextField tfname;
	@FXML
	
	private TextField tflevel;
	@FXML

	private TextField tfid;
	@FXML
	
	private Button order;
	@FXML
	private Button staffMangaement;
	@FXML
	private Button goodsCheck;
	@FXML
	private ImageView photo;
	public String a="";
	public  static sender model = new sender();
	
	public void goodsCheck() {
		Stage stage = (Stage)order.getScene().getWindow();
		stage.close();
		try {
			GoodsController lg = new GoodsController();
			lg.start(stage);
		}catch(Exception e) {
			
			e.printStackTrace();
		}
	}
	
	/*public void manage() {
		Stage stage = (Stage)order.getScene().getWindow();
		stage.close();
		try {
			StaffController stfg = new StaffController();
			stfg.start(stage);
		}catch(Exception e) {
			
			e.printStackTrace();
		}
	
	}
	
	public void excel() {
		Stage stage = (Stage)order.getScene().getWindow();
		stage.close();
		try {
			chartController cc = new chartController();
			cc.start(stage);
		}catch(Exception e) {
			
			e.printStackTrace();
		}
	
	}*/

	
	/*public void initialize(URL arg0, ResourceBundle arg1) {
		// TODO Auto-generated method stub
		 model.textProperty().addListener((obs, oldText, newText) -> tfid.setText(newText));
		
		 int id=Integer.parseInt(model.getText().trim());
		 staff stf=staffDao.SearchById(id);
		 //System.out.print(stf.getLevel());
		 tfname.setText(stf.getName());
		 tfid.setText(stf.getId()+"");
		 if(stf.getLevel().equals("服务员")) 
		 {
			  tflevel.setText("服务员");}
		 else if(stf.getLevel().equals("管理员"))
			 tflevel.setText("管理员");
		 photo.setImage(new Image(stf.getImage()));
	}*/
	public void manage() {
		  if(a.equals("管理员")) { 
		   Stage stage = (Stage)order.getScene().getWindow();
		   stage.close();
		   try {
		    StaffController stfg = new StaffController();
		    stfg.start(stage);
		   }catch(Exception e) {
		    
		    e.printStackTrace();
		   }
		  }else {
		   JOptionPane.showMessageDialog(null, "您无权访问该功能"); 
		  }
		 
		 }
		 
	public void excel() {
		 if(a.equals("管理员")) { 
		  Stage stage = (Stage)order.getScene().getWindow();
		  stage.close();
		  try {
		   chartController cc = new chartController();
		   cc.start(stage);
		  }catch(Exception e) {
		   
		   e.printStackTrace();
		  }
		 }else {
		  JOptionPane.showMessageDialog(null, "您无权访问该功能"); 
		 }
		 
		 }
	public void initialize(URL arg0, ResourceBundle arg1) {
		  // TODO Auto-generated method stub
		   model.textProperty().addListener((obs, oldText, newText) -> tfid.setText(newText));
		  
		   int id=Integer.parseInt(model.getText().trim());
		   staff stf=staffDao.SearchById(id);
		   //System.out.print(stf.getLevel());
		   tfname.setText(stf.getName());
		   tfid.setText(stf.getId()+"");
		   if(stf.getLevel().equals("服务员")) 
		   {
		    a="服务员";
		     tflevel.setText("服务员");}
		   else if(stf.getLevel().equals("管理员"))
		   {  
		    tflevel.setText("管理员");
		    a="管理员";
		   }
		   photo.setImage(new Image(stf.getImage()));
		 }
	
	public void order() {
		FXMLLoader fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource("View1/MainMenu.fxml"));
        MainMenuController mainController = fxmlLoader.getController();
        Stage mainStage =(Stage) order.getScene().getWindow();
        //读入布局
        try {
        	Parent root = fxmlLoader.load();
        	Scene scene = new Scene(root);
        	mainStage.setTitle("加州阳光POS系统");
        	//mainStage.setMaximized(true);
        	mainStage.setScene(scene);
        	mainStage.show();
        }catch(Exception e) {
			
			e.printStackTrace();
		}  
	}
	
	public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("View1/MainView.fxml"));
        primaryStage.setScene(new Scene(root));
        primaryStage.setResizable(false);
        primaryStage.show();
    }
	
	
}
